local zhuguan = fk.CreateSkill{
    name = "history__zhuguan",
    tags = { Skill.Compulsory },
}

Fk:loadTranslationTable{
    ["history__zhuguan"] = "筑关",
    [":history__zhuguan"] = "锁定技，你使用红色基本牌时，你摸一张牌，你以此法获得的牌不计入手牌上限：回合开始时，你弃置以此法获得的手牌。",

    ["@@zhuguan_obtained-inhand"] = "筑关",
}

-- 使用红色基本牌时摸牌
zhuguan:addEffect(fk.CardUsing, {
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(zhuguan.name) and 
               data.card.color == Card.Red and data.card.type == Card.TypeBasic
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        -- 摸一张牌
        local drawn_cards = player:drawCards(1, zhuguan.name)
        -- 为摸到的牌添加标记，表示这是筑关技能获得的牌
        for _, card_id in ipairs(drawn_cards) do
            room:setCardMark(Fk:getCardById(card_id), "@@zhuguan_obtained-inhand", 1)
        end
    end,
})

-- 回合开始时弃置以此法获得的手牌
zhuguan:addEffect(fk.EventPhaseStart, {
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(zhuguan.name) and player.phase == Player.Start
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local handcards = player:getCardIds(Player.Hand)
        local zhuguan_cards = {}
        
        -- 找出所有通过筑关技能获得的手牌
        for _, card_id in ipairs(handcards) do
            local card = Fk:getCardById(card_id)
            if card:getMark("@@zhuguan_obtained-inhand") > 0 then
                table.insert(zhuguan_cards, card_id)
            end
        end
        
        -- 弃置这些手牌
        if #zhuguan_cards > 0 then
            room:throwCard(zhuguan_cards, zhuguan.name, player, player)
        end
    end,
})

-- 手牌上限技能：通过筑关获得的牌不计入手牌上限
zhuguan:addEffect("maxcards", {
    exclude_from = function(self, player, card)
        return card:getMark("@@zhuguan_obtained-inhand") > 0
    end,
})



return zhuguan
